﻿using System;
using System.Collections.Generic;
using System.Text;

namespace daSyntaxAnalyser.SyntaxTree
{
    using daBase.Objects;

    public class InterfaceDefinitionElement : SyntaxTreeElement, ITypeElement
    {
        private IdElement parent;
        private ConstExpressionElement guid;
        private List<ISectionElementElement> elements;

        public IdElement Parent { get { return parent; } set { parent = value; } }
        public ConstExpressionElement Guid { get { return guid; } set { guid = value; } }
        public List<ISectionElementElement> Elements { get { return elements; } set { elements = value; } }

        public InterfaceDefinitionElement(TokenInfo StartInfo, IdElement Parent, ConstExpressionElement Guid, List<ISectionElementElement> Elements, List<TokenInfo> Comments)
            : base(StartInfo, Comments)
        {
            parent = Parent;
            guid = Guid;
            elements = Elements;
        }

        public override string ToString()
        {
            return string.Format("interface{0}{1}{2}{3}",
                (parent != null) ? string.Format(" ({0})", parent) : string.Empty,
                (guid != null) ? string.Format("\r\n[{0}]", guid) : string.Empty,
                ((elements != null) && (elements.Count > 0)) ? string.Format("\r\n{0}", Tabulate(elements.Join("\r\n"))) : string.Empty,
                ((parent != null) || (guid != null) || ((elements != null) && (elements.Count > 0))) ? "\r\nend" : string.Empty);
        }

        protected override IEnumerator<ISyntaxTreeElement> CreateEnumerator()
        {
            if (parent != null)
                yield return parent;
            if (guid != null)
                yield return guid;
            if (elements != null)
                foreach (ISectionElementElement element in elements)
                    yield return element;
        }
    }
}
